package com.example.demo.Controller;

import com.example.demo.Common.Constants;
import com.example.demo.Common.IndexConfigTypeEnum;
import com.example.demo.Service.CarouselService;
import com.example.demo.Service.IndexConfigService;
import com.example.demo.Util.Result;
import com.example.demo.Util.ResultGenerator;
import com.example.demo.VO.IndexCarouselVO;
import com.example.demo.VO.IndexConfigProductVO;
import com.example.demo.VO.IndexInfoVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
public class HomeController {

    @Resource
    private CarouselService carouselService;

    @Resource
    private IndexConfigService indexConfigService;

    /*@GetMapping("/home")
    @ApiOperation(value = "获取首页数据", notes = "轮播图、新品、推荐等")
    public Result<IndexInfoVO> indexInfo() {
        IndexInfoVO indexInfoVO = new IndexInfoVO();
        List<IndexCarouselVO> carousels = carouselService.getCarouselsForIndex(Constants.INDEX_CAROUSEL_NUMBER);
        List<IndexConfigProductVO> hotProducts = indexConfigService.getConfigProductsForIndex(IndexConfigTypeEnum.INDEX_PRODUCTS_HOT.getType(), Constants.INDEX_PRODUCTS_HOT_NUMBER);
        List<IndexConfigProductVO> newProducts = indexConfigService.getConfigProductsForIndex(IndexConfigTypeEnum.INDEX_PRODUCTS_NEW.getType(), Constants.INDEX_PRODUCTS_NEW_NUMBER);
        List<IndexConfigProductVO> recommendProducts = indexConfigService.getConfigProductsForIndex(IndexConfigTypeEnum.INDEX_PRODUCTS_RECOMMOND.getType(), Constants.INDEX_PRODUCTS_RECOMMOND_NUMBER);
        indexInfoVO.setCarousels(carousels);
        indexInfoVO.setHotProducts(hotProducts);
        indexInfoVO.setNewProducts(newProducts);
        indexInfoVO.setRecommendProducts(recommendProducts);
        return ResultGenerator.genSuccessResult(indexInfoVO);
    }*/

    @GetMapping("/home")
    @ApiOperation(value = "获取首页数据", notes = "轮播图、商品等")
    public Result<IndexInfoVO> indexInfo() {
        IndexInfoVO indexInfoVO = new IndexInfoVO();
        List<IndexCarouselVO> carousels = carouselService.getCarouselsForIndex(Constants.INDEX_CAROUSEL_NUMBER);
        List<IndexConfigProductVO> products = indexConfigService.getAllProducts();
      //  List<IndexConfigProductVO> newProducts = indexConfigService.getConfigProductsForIndex(IndexConfigTypeEnum.INDEX_PRODUCTS_NEW.getType(), Constants.INDEX_PRODUCTS_NEW_NUMBER);
       // List<IndexConfigProductVO> recommendProducts = indexConfigService.getConfigProductsForIndex(IndexConfigTypeEnum.INDEX_PRODUCTS_RECOMMOND.getType(), Constants.INDEX_PRODUCTS_RECOMMOND_NUMBER);
        indexInfoVO.setCarousels(carousels);
        indexInfoVO.setProducts(products);
       // indexInfoVO.setHotProducts(hotProducts);
       // indexInfoVO.setNewProducts(newProducts);
       // indexInfoVO.setRecommendProducts(recommendProducts);
        return ResultGenerator.genSuccessResult(indexInfoVO);
    }






}
